package com.cdream.basic.thread;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

/**
 * 偏向锁开关和偏向锁延迟
 * -XX:+UseBiasedLocking -XX:BiasedLockingStartupDelay=40
 * @author cdream
 * @date 2022/2/7
 */
@Slf4j(topic = "object-head")
public class ObjectHeader {
    public static void main(String[] args) throws InterruptedException {
        Object o = new Object();
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
        ThreadUtil.sleep(5000);
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
        // synchronized (o) {
        //     System.out.println(ClassLayout.parseInstance(o).toPrintable());
        // }
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                synchronized (o) {
                    System.out.println(ClassLayout.parseInstance(o).toPrintable());
                }
            }).start();
            // Thread.sleep(1000);

        }


        Thread.sleep(1000);
        System.out.println(ClassLayout.parseInstance(o).toPrintable());

    }
}
